package com.leetcode.math;

public class MaxProfitMulti {
    public static void main(String[] args) {

    }

    public int maxProfit(int[] prices) {
        int profitSum = 0;
        int minPrice = Integer.MAX_VALUE;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < minPrice) {
                minPrice = prices[i];
            } else if (prices[i] > minPrice) {
                profitSum += prices[i] - minPrice;
                minPrice = prices[i];
            }
        }
        return profitSum;
    }
}
